﻿using System;

using LeanEngine.Entity;
using LeanEngine.Validation;
using System.Data.Linq.Mapping;

namespace LeanEngine.Business.Security.Entity
{
    /// <summary>
    /// Represents an special authorization policy for a membership.
    /// </summary>
    [Table(Name = "ExceptionPolicy")]
    public class ExceptionPolicy : PlainEntity
    {
        /// <summary>
        /// Gets or sets the membership owner of the policy.
        /// </summary>
        [Column(Name = "MembershipID", IsPrimaryKey = true)]
        [IsNotNullAndHasPrimaryKeysFilledAttribute(typeof(Resource.ErrorMessages), "ExceptionPolicyMembershipRequired")]
        public Membership Membership
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the application method to which the policy applies.
        /// </summary>
        [Column(Name = "FuncID", IsPrimaryKey = true)]
        [IsNotNullAndHasPrimaryKeysFilledAttribute(typeof(Resource.ErrorMessages), "ExceptionApplicationMethodRequired")]
        public ApplicationMethod Method
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a flag indicating whether a membership has access or not.
        /// </summary>
        [Column(Name = "AllowedAccess")]
        public bool AllowedAccess
        {
            get;
            set;
        }
    }
}
